package com.iot.controller;

import com.iot.dto.DeviceRegisterDTO;
import com.iot.relay.ExchangeData;
import com.iot.service.DeviceInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "设备管理接口")
@RequestMapping("/device")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DeviceController {

    private final DeviceInfoService deviceInfoService;

    @PostMapping("/register")
    @ApiOperation(value = "设备注册", notes = "设备注册")
    public ExchangeData<Object> register(@RequestBody DeviceRegisterDTO meterDto) {
        ExchangeData<Object> exchangeData = new ExchangeData<>();
        Long resultId = deviceInfoService.register(meterDto);
        exchangeData.setId(resultId);
        exchangeData.setMessage("设备注册成功");
        return exchangeData;
    }

}
